package com.baizhi.utils.apache.io;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class FileUtilsTest {

    /**
     * 读取文件内容为一个字符串
     */
    @Test
    public void test1() throws IOException {
        String path = "src/main/resources/1.txt";
        String str = FileUtils.readFileToString(new File(path), StandardCharsets.UTF_8);
        System.out.println(str);
    }

    /**
     * 读取文件内容为一个List
     */
    @Test
    public void test2() throws IOException {
        String path = "src/main/resources/1.txt";
        List<String> list = FileUtils.readLines(new File(path), StandardCharsets.UTF_8);
        System.out.println(list);
    }

    /**
     * 获取文件的baseName
     * 获取文件的后缀
     */
    @Test
    public void test3() {
        String path = "src/main/resources/1.txt";
        System.out.println(FilenameUtils.getBaseName(path));
        System.out.println(FilenameUtils.getExtension(path));
    }
}
